import { defineConfig } from 'vite'
import react from '@vitejs/plugin-react'
import vitePluginImp from 'vite-plugin-imp'
import lessToJS from 'less-vars-to-js'
import { readFileSync } from 'fs'
import { resolve } from 'path'

const themeVariables = lessToJS(readFileSync(resolve(__dirname, './config/variables.less'), 'utf8'))

// https://vitejs.dev/config/
export default defineConfig({
  base: './',
  plugins: [
    react(),
    vitePluginImp({
      optimize: true,
      libList: [
        {
          libName: 'antd',
          style: (name) => `antd/es/${name}/style`
        }
      ]
    })
  ],
  css: {
    preprocessorOptions: {
      less: {
        javascriptEnabled: true,
        modifyVars: themeVariables
      }
    }
  },
  resolve: {
    alias: [{ find: '@', replacement: resolve(__dirname, 'src') }]
  },
  server: {
    port: 8081
    // proxy: {
    //   '/api': {
    //     target: 'http://bistudio-server-tjpm.internal.weimobpl.com',
    //     ws: true,
    //     changeOrigin: true,
    //     rewrite: (path) => path.replace('/api/', '/')
    //   }
    // }
  }
})
